package com.element.security.server.config;

import com.common.core.exception.ExceptionFactory;
import com.element.security.constant.SecurityParams;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.redis.RedisTokenStore;

import javax.annotation.Resource;

/**
 * @auther zhangwj
 * @date 2021/3/11 上午9:40
 */
@Configuration
public class TokenStoreConfig {

    @Resource
    private RedisConnectionFactory redisConnectionFactory;

    public TokenStore getTokenStore() {
        if (null == redisConnectionFactory) {
            throw ExceptionFactory.sysException("redisConnectionFactory is null");
        }
        RedisTokenStore tokenStore = new RedisTokenStore(redisConnectionFactory);;
        tokenStore.setPrefix(SecurityParams.SPRING_SECURITY_TOKEN_KEY);
        return tokenStore;
    }
}
